//
//  JPMainTabBarViewController.swift
//  JPWeibo
//
//  Created by 哇咔咔 on 16/9/19.
//  Copyright © 2016年 jp. All rights reserved.
//

import UIKit

class JPMainTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = JPMainTabBar()
        mainTabBar.composeDelegate = self
        mainTabBar.composeButtonClosure = {
            print("我是闭包的回调")
            let composeView = JPComposeView.init(frame: CGRect(x: 0, y: 0, width: screenWidth, height: ScreenHeight))
            composeView.show(target: self)
        }
        self.setValue(mainTabBar, forKey: "tabBar")

        addChildViewController(childController: JPHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: JPMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: JPDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: JPProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }
    
    //重载添加自控制器方法
    func addChildViewController(childController: UIViewController ,title: String , imageName: String) {
        
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14)], for: .normal)
        
        let navVC = JPNavigationController(rootViewController: childController)
        
        addChildViewController(navVC)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

extension JPMainTabBarViewController: JPMainTabBarDelegate {
    
    func didSelectedComposeButton() {
        print("我是代理对象调用过来的")
    }
}






